package org.xjtu.weteam.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xjtu.weteam.common.repository.FileRepository;
import org.xjtu.weteam.mapper.FileMapper;
import org.xjtu.weteam.model.domain.File;
import org.xjtu.weteam.model.dto.FileDTO;
import org.xjtu.weteam.service.FileService;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Service
public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements FileService {
    @Autowired
    private FileMapper fileMapper;

    @Override
    public List<FileDTO> listFiles(Integer projectId, Integer userId) {
        return fileMapper.listFiles(projectId, userId);
    }

    @Override
    public int updateFiles(File file) {
        return fileMapper.updateFiles(file);
    }

    @Override
    public int deleteFile(Integer fileId) {
        return fileMapper.deleteFile(fileId);
    }

    @Override
    public File getFileById(Integer fileId) {
        return fileMapper.getFileById(fileId);
    }


    @Override
    public String getFilePath(Integer fileId) {
        return fileMapper.getFilePath(fileId);
    }

    @Override
    public Boolean rename(String newFileName, Integer fileId) {
        fileMapper.updateFileName(newFileName, fileId);
        return true;
    }

    @Override
    public Boolean moveFile(Integer fileId, Integer projectId) {
        fileMapper.updateProjectId(fileId, projectId);
        return true;
    }
}
